<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <include file="Public/sidebar"/>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs"/>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set"/>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form class="form-horizontal" id='form' role="form" action="{$form_url}" method="post">
                            <input type="hidden" name='id' value="{$class.id}" />
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 班级名称 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="name" id="name" class="rcol-xs-10 col-sm-5"
                                        placeholder="如：小红帽班"   value="{$class.name}">
                                    <span class="help-inline col-xs-12 col-sm-7">
                                                <span class="middle"></span>
                                            </span>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 班级级别 </label>
                                <div class="col-sm-9">
                                   <select id="class_type" name="class_type" class="multiselect">
                                        <option value="0">--请选择班级--</option>
                                        <volist name="class_type" id="val">
                                            <option <if condition="$class['class_type'] eq $val['id']">selected='selected' </if> value="{:$val['id']}">{:$val['name']}</option>
                                        </volist>
                                    </select>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 班主任 </label>
                                <div class="col-sm-9">
                                    <select id="class_manager" name="class_manager" class="multiselect">
                                    </select>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 生活老师 </label>
                                <div class="col-sm-9">
                                    <select id="life_teacher" name="life_teacher" class="multiselect">
                                    </select>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 配班老师 </label>
                                <div class="col-sm-9">
                                    <select id="class_teacher" name="class_teacher" class="multiselect">
                                    </select>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-2"> 报名费用 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="price" id="price"
                                           class="col-xs-10 col-sm-5" value="{$class.price}">
                                    <span class="help-inline col-xs-12 col-sm-7">
                                                <span class="middle"></span>
                                            </span>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-2"> 班级预留名额 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="num" id="num"
                                           class="col-xs-10 col-sm-5" value="{$class.num}">
                                    <span class="help-inline col-xs-12 col-sm-7">
                                                <span class="middle"></span>
                                            </span>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 班级简介 </label>
                                 <div class="col-sm-9">
                                        <textarea name="desc" id="desc"
                                                  style="width:100%;height:400px;visibility:hidden;">{$class['desc']}</textarea>
                                </div>

                            </div>
                            <div class="space-4"></div>

                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info submit" type="button">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>
                        </form>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file="Public/footer"/>

</div><!-- /.main-container -->

<include file="Public/footerjs"/>
<!-- inline scripts related to this page -->
<script src="__PUBLIC__/qwadmin/js/date-time/bootstrap-datepicker.js"></script>
<script type="text/javascript">
    $(function () {
        $("#tabs").tabs();
        var editor = KindEditor.create('textarea[name="desc"]', {
            uploadJson: '__PUBLIC__/kindeditor/php/upload_json.php',
            fileManagerJson: '__PUBLIC__/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function () {
                this.sync();
            }
        });

        //加载
         var class_type = $('#class_type').val();
        if(class_type != 0){
                var class_manager_num = "{:$class['class_manager']}";
                var life_teacher_num = "{:$class['life_teacher']}";
                var class_teacher_num = "{:$class['class_teacher']}";
                $.ajax({
                    url: "{:U('Class/getTeacher')}",
                    type: 'POST',
                    dataType: 'JSON',
                    data: {'class_id': class_type},
                    success : function (res){
                        if(res.res == 1){
                            var class_manager = '<option value="0">--请选择班主任--</option>';
                            var life_teacher = '<option value="0">--请选择生活老师--</option>';
                            var class_teacher = '<option value="0">--请选择配班老师--</option>';
                            var data = res.data;
                            for (var i=0 ;i<data.length;i++) {
                                if(data[i]['teacher_type'] == 1){
                                    if(data[i]['uid'] == class_manager_num){
                                        class_manager += "<option selected='selected' value='"+data[i]['uid']+"'>"+data[i]['name']+"</option>";
                                    }else{
                                        class_manager += "<option value='"+data[i]['uid']+"'>"+data[i]['name']+"</option>";
                                    }
                                }
                                if(data[i]['teacher_type'] == 2){
                                    if(data[i]['uid'] == life_teacher_num){
                                        life_teacher += "<option selected='selected' value='"+data[i]['uid']+"'>"+data[i]['name']+"</option>";
                                    }else{

                                        life_teacher += "<option value='"+data[i]['uid']+"'>"+data[i]['name']+"</option>";
                                    }
                                }
                                if(data[i]['teacher_type'] == 3){
                                    if(data[i]['uid'] == class_teacher_num){
                                        class_teacher += "<option selected='selected' value='"+data[i]['uid']+"'>"+data[i]['name']+"</option>";
                                    }else{

                                        class_teacher += "<option value='"+data[i]['uid']+"'>"+data[i]['name']+"</option>";
                                    }
                                }
                            }
                            $('#class_manager').html(class_manager);
                            $('#class_teacher').html(class_teacher);
                            $('#life_teacher').html(life_teacher);
                        }else{
                            var class_manager = '<option value="0">--没有班主任信息，请添加--</option>';
                            var class_teacher = '<option value="0">--没有配班老师信息，请添加--</option>';
                            var life_teacher = '<option value="0">--没有生活老师信息，请添加--</option>';
                            $('#class_manager').html(class_manager);
                            $('#class_teacher').html(class_teacher);
                            $('#life_teacher').html(life_teacher);
                        }
                    }   
                })
    
        }
    $('.submit').click(function(event) {
        var name = $.trim($('#name').val());
        var class_type = $('#class_type').val();
        var class_manager = $('#class_manager').val();
        var life_teacher = $('#life_teacher').val();
        var class_teacher = $('#class_teacher').val();
        var price = $('#price').val();
        var num = $('#num').val();
        var desc = $.trim($('#desc').val());
        if (name == '') {
            bootbox.dialog({
                title: '友情提示：',
                message: "班级名称必须填写!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        if (class_type == 0) {
            bootbox.dialog({
                title: '友情提示：',
                message: "请选择班级级别!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        if (class_manager == 0) {
            bootbox.dialog({
                title: '友情提示：',
                message: "请选择班主任!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        if (life_teacher == 0) {
            bootbox.dialog({
                title: '友情提示：',
                message: "请选择生活老师!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        if (class_teacher == 0) {
            bootbox.dialog({
                title: '友情提示：',
                message: "请选择配班老师!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        if (price == '') {
            bootbox.dialog({
                title: '友情提示：',
                message: "请填写报名费用!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        if (isNaN(price)) {
            bootbox.dialog({
                title: '友情提示：',
                message: "报名费用为阿拉伯数字!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        if (num == '') {
            bootbox.dialog({
                title: '友情提示：',
                message: "请填写班级名额!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        if (isNaN(num)) {
            bootbox.dialog({
                title: '友情提示：',
                message: "报名费用为阿拉伯数字!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        if (desc == '') {
            bootbox.dialog({
                title: '友情提示：',
                message: "请填写班级简介!",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
            return;
        }
        $('#form').submit();
    });
});
$('#class_type').change(
    function(event) {
        var class_type = $('#class_type').val();

        $.ajax({
            url: "{:U('Class/getTeacher')}",
            type: 'POST',
            dataType: 'JSON',
            data: {'class_id': class_type},
            success : function (res){
                if(res.res == 1){
                    var class_manager = '<option value="0">--请选择班主任--</option>';
                    var life_teacher = '<option value="0">--请选择生活老师--</option>';
                    var class_teacher = '<option value="0">--请选择配班老师--</option>';
                    var data = res.data;
                    for (var i=0 ;i<data.length;i++) {
                        if(data[i]['teacher_type'] == 1){
                            class_manager += "<option value='"+data[i]['uid']+"'>"+data[i]['name']+"</option>";
                        }
                        if(data[i]['teacher_type'] == 2){
                            life_teacher += "<option value='"+data[i]['uid']+"'>"+data[i]['name']+"</option>";
                        }
                        if(data[i]['teacher_type'] == 3){
                            class_teacher += "<option value='"+data[i]['uid']+"'>"+data[i]['name']+"</option>";
                        }
                    }
                    $('#class_manager').html(class_manager);
                    $('#class_teacher').html(class_teacher);
                    $('#life_teacher').html(life_teacher);
                }else{
                    var class_manager = '<option value="0">--没有班主任信息，请添加--</option>';
                    var class_teacher = '<option value="0">--没有配班老师信息，请添加--</option>';
                    var life_teacher = '<option value="0">--没有生活老师信息，请添加--</option>';
                    $('#class_manager').html(class_manager);
                    $('#class_teacher').html(class_teacher);
                    $('#life_teacher').html(life_teacher);
                }
            }   
        })
        
});
</script>
</body>
</html>
